package com.github.edu.web.db.controller;
import com.github.admin.edu.assembly.common.entity.JsonArray;
import com.github.admin.edu.assembly.page.entity.Pager;
import com.github.edu.client.common.annotation.*;
import com.github.edu.client.common.controller.BaseController;
import com.github.edu.db.server.api.entity.TableManager;
import com.github.edu.web.db.service.DbManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-7-31
 */
@Controller
@RequestMapping("/uc/db")
public class DbManagerController extends BaseController<TableManager,String> {

    @Autowired
    private DbManagerService service;


    @QueryAll
    public String index(ModelMap modelMap, HttpServletRequest request, TableManager sysOauth, Pager pager) {
        if(null==pager){
            pager=new Pager();
        }
        pager.setDirection("DESC");
        String[] strs={"id"};
        pager.setOrder(strs);
        JsonArray<TableManager> jsonArray=service.getAllByPage(sysOauth,pager);
        return super.index(modelMap,sysOauth,jsonArray,"db","表对象管理",
                "编码:id","表名称:tableName","每页条目:pageRows","是否树:isTree","表单类型:formTypes");
    }

    @New
    public String add(ModelMap modelMap, TableManager sysOauth, HttpServletRequest request) {
        return super.newIndex(modelMap,sysOauth,"db","新增授权服务");
    }

    @Save
    public String saveOrUpdate(ModelMap modelMap, TableManager sysOauth, HttpServletRequest request) {
        sysOauth=service.saveOrUpdate(sysOauth);
        return super.saveObject(modelMap,sysOauth,"保存成功！","db","保存授权服务");
    }

    @Open
    public String openEntity(ModelMap modelMap,@PathVariable("id") String id) {
        TableManager application=service.getEntity(id);
        return super.openEntity(modelMap,application,"db","查看详情");
    }
    @Edit
    public String edit(ModelMap modelMap,@PathVariable("id") String s) {
        TableManager application=service.getEntity(s);
        return super.newIndex(modelMap,application,"db","编辑授权服务");
    }

    @Delete
    public String delete( String ids) {
        return service.delete(ids);
    }
}
